package cn.wtg.kotlinlib.SingleActivityMulFragmentUi

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import cn.wtg.kotlinlib.baseUi.BaseBindingActivity
import cn.wtg.kotlinlib.baseUi.BaseFragment
import cn.wtg.kotlinlib.utils.FragmentHelper

/**
 * author: wtg
 * time: 2022/11/15
 * desc: 单activity+多fragment的基础activity
 */
abstract class BaseBindingBackStackFragmentActivity<out B : ViewDataBinding> :
    BaseBindingActivity<B>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (savedInstanceState != null) {
            savedInstanceState.putParcelable("android:support:fragments", null)
        } else {
            val fragment = loadFragment()
            FragmentHelper.replaceNoBackStackFragment(
                supportFragmentManager,
                fragment,
                fragment.TAG,
                getContainerId()
            )
        }
    }

    /**
     * 获取第一次加载的fragment
     * @return fragment
     */
    abstract fun loadFragment(): BaseFragment

    /**
     * 获取布局容器id
     * @return id
     */
    abstract fun getContainerId(): Int
}